package com.wk.net.heartbeat.handler;

/**
 * 任务类：检查收到的心跳，以确定掉线和上线的对象
 * 
 * @author Bai Yu
 *
 */
class CheckHeartbeat implements Runnable {
	public CheckHeartbeat(HeartbeatObserver observer, AbsenceListener absenceListener) {
		this.observer = observer;
		this.absenceListener = absenceListener;
	}

	@Override
	public void run() {
		synchronized (observer) {
			observer.check();
		}

		if (absenceListener != null) {
			absenceListener.onAbsent(observer.getRecentlyAbsent());
		}
	}

	private HeartbeatObserver observer;
	private AbsenceListener absenceListener;
}
